home *** CD-ROM | disk | FTP | other *** search
- { SPX Library Version 3.0 Copyright 1993 Scott D. Ramsay }
-
- SPX_FNC contains general functions and procedures that are used
- by most of the units.
-
- ───────────────────────────────────────────────────────────────────────────
- function sgn(h:integer):integer;
-
- Returns -1 if H is less than zero
- 1 if H is greater than zero
- 0 if H is equal to zero
- ───────────────────────────────────────────────────────────────────────────
- function max(a,b:integer):integer;
-
- returns the maximum integer from the paramaters
-
- ───────────────────────────────────────────────────────────────────────────
- function min(a,b:integer):integer;
-
- returns the minimum integer from the paramaters
-
- ───────────────────────────────────────────────────────────────────────────
- function strint(s:string):longint;
-
- converts a four character string to a longint value;
-
- The characters are repesented at hi and lo byte values of the longint.
-
- EXAMPLE:
-
- var
- s : string;
- l : longint;
- begin
- s := 'AT';
- l := strint(s); { l := 21569 or $00005441 }
- end;
-
- ───────────────────────────────────────────────────────────────────────────
- function intstr(l:longint):string;
-
- converts a longint to a four character string.
-
- EXAMPLE:
-
- var
- s : string;
- l : longint;
- begin
- s := intstr(21569); { s := 'AT'#0#0; }
- end;
-
- ───────────────────────────────────────────────────────────────────────────
- function ups(s:string):string;
-
- returns S in all uppercase letters.
-
- ───────────────────────────────────────────────────────────────────────────
- function st(h:longint):string;
-
- converts H to a string
-
- EXAMPLE:
-
- var
- s : string;
- begin
- s := st(123); { s := '123';
- end;
-
- ───────────────────────────────────────────────────────────────────────────
- function compare(s1,s2:string):boolean;
-
- Compares two strings returns true if they are equal up to the length
- of S1.
-
- EXAMPLE:
-
- compare('SPXLIB','SPX') returns FALSE
- compare('SPX','SPXLIB') returns TRUE
-
- ───────────────────────────────────────────────────────────────────────────
- function dtcmp(var s1,s2;size:word):boolean;
-
- Same as function CMP. Here for compatibility
-
- ───────────────────────────────────────────────────────────────────────────
- function cmp(var s1,s2;size:word):boolean;
-
- Compares to variables of unknown types.
-
- S1,S2: objects of any type to compare
- SIZE: size of objects
-
- Returns true if the bytes within S1 and S2 are equal
-
- ───────────────────────────────────────────────────────────────────────────
- function lz(i,w:longint):string;
-
- Converts a longint to a string with leading zeros.
-
- I: Integer to convert
- W: Number of spaces to place zeros
-
- EXAMPLE:
-
- var
- s : string;
- begin
- s := lz(1234,7); { s := '0001234'; }
- end;
-
- ───────────────────────────────────────────────────────────────────────────
- function vl(h:string):longint;
-
- converts a string to a longint value
-
- H: string to convert
-
- ───────────────────────────────────────────────────────────────────────────
- function spaces(h:integer):string;
-
- Creates a string with H number of spaces
-
- EXAMPLE:
-
- s := spaces(10); { s := ' '; (* ten spaces *) }
-
- ───────────────────────────────────────────────────────────────────────────
- function repstr(h:integer;ch:char):string;
-
- Creates a string with H number of the character ch.
-
-
- EXAMPLE:
-
- s := repstr(10,'A'); { s := 'AAAAAAAAAA'; }
-
- ───────────────────────────────────────────────────────────────────────────
- function ifix(var a:integer;min,max:integer):boolean;
-
- Sets an integer to the range min..max.
-
- A: Value to change
- MIN: Minimum value A can be
- MAX: Maximum value A can be
-
- Returns TRUE if the variable was changed.
-
- EXAMPLE:
-
- {$X+ } { enable extended syntax }
-
- var
- a,b,c : integer;
- modified,
- didChange : boolean;
- begin
- a := -10;
- b := 112;
- c := 50;
- didChange := ifix(a,0,100);
- modified := ifix(c,0,100);
- ifix(b,0,100);
-
- { didChange := TRUE }
- { modified := FALSE }
- { a := 0 }
- { b := 100 }
- { c := 50 }
- end;
-
- ───────────────────────────────────────────────────────────────────────────
- function rfix(var a:real;min,max:real):boolean;
-
- Sets a real to the range min..max.
-
- A: Value to change
- MIN: Minimum value A can be
- MAX: Maximum value A can be
-
- Returns TRUE if the variable was changed.
-
- EXAMPLE
- See function ifix
- ───────────────────────────────────────────────────────────────────────────
- function anything(s:string):boolean;
-
- Returns TRUE if the S is not an empty string or if any of
- the characters in S is in the range #32..#255 (ascii)
-
- ───────────────────────────────────────────────────────────────────────────
- function exist(f:string):boolean;
-
- Returns TRUE if the file exist on disk
-
- F: The file to check. Can have full file spec.
- ───────────────────────────────────────────────────────────────────────────
- function TPerror(errorcode:integer) : string;
-
- Returns an Turbo Pascal error string
-
- ERRORCODE: value generated by the funciton IOresult
-
- ───────────────────────────────────────────────────────────────────────────
- procedure funpad(var s:string);
-
- Removes all leading spaces from the string S
-
- ───────────────────────────────────────────────────────────────────────────
- procedure unpad(var s:string);
-
- Removes all trailing spaces from the string S
-
- ───────────────────────────────────────────────────────────────────────────
- procedure munpad(var s:string;b:byte);
-
- Cuts string S to length B. Then removes all trailing charaters
- that are in the range #0..#31.
-
- ───────────────────────────────────────────────────────────────────────────
- function fpad(s:string;h:integer):string;
-
- Returns the string S with length H by adding trailing spaces
- if nessasary.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure pad(var s:string;h:integer);
-
- Same as fpad. Changes string S to length H by adding trailing spaces
- if nessasary.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fix(var s:string;h:string);
-
- Adds an extension to the file name S if one does not exist.
-
- S: String to check for extenstion
- H: extension to add
-
- EXAMPLE:
-
- s1 := 'mypic';
- s2 := 'mypic2.';
- s3 := 'mypic3.dog';
- s4 := 'mypic4.pcx';
-
- fix(s1,'.PCX'); { s1 := 'mypic.PCX' }
- fix(s2,'.PCX'); { s2 := 'mypic2.' }
- fix(s3,'.PCX'); { s3 := 'mypic3.dog' }
- fix(s4,'.PCX'); { s4 := 'mypic.pcx' }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fixh(var s:string);
-
- Converts all characters in S that are in the range #0..#31 to spaces
-
- ───────────────────────────────────────────────────────────────────────────
- function range(x,y,x1,y1,x2,y2:integer) : boolean;
-
- Returns TRUE if the point (x,y) is in the rectangle (x1,y1,x2,y2)
-
- ───────────────────────────────────────────────────────────────────────────
- function rrange(x,y,x1,y1,x2,y2:real) : boolean;
-
- Returns TRUE if the point (x,y) is in the rectangle (x1,y1,x2,y2)
-
- ───────────────────────────────────────────────────────────────────────────
- function between(x,x1,x2:longint):boolean;
-
- Returns TRUE if X is between X1 and X2
-
- ───────────────────────────────────────────────────────────────────────────
- function fspaces(s:string;skip:byte):string;
-
- Returns a string portion in S delimited by spaces. Returns an empty
- string if one is not found.
-
- S: string to search
- SKIP: number of strings to skip
-
- EXAMPLE:
-
- s := 'Now is the time for all good men to';
-
- writeln(fspaces(s,0)); { outputs 'Now' }
- writeln(fspaces(s,3)); { outputs 'time' }
- writeln(fspaces(s,9)); { outputs '' }
-
- ───────────────────────────────────────────────────────────────────────────
- function GetPtr(p:pointer;offset:longint):pointer;
-
- Creates a new pointer at P+offset. Adjusts for segment boundries.
- Returns the new pointer location. Note: offset MUST be positive or zero.
-
- P: pointer to adjust
- OFFSET: offset for the pointer (in bytes)
-
- EXAMPLE:
-
- var
- p : pointer;
-
- p := GetPtr(SomePointer,88000);
-
- { p points to 88000 bytes past SomePointer }
-
- ───────────────────────────────────────────────────────────────────────────
- function sar(value:integer;shift:byte):integer;
-
- Shift arithmetic right. Same as SHR but maintains the signed (hi) bit.
-
- VALUE: integer value to shift.
- SHIFT: bits to shift
-
- note: I don't know why Borland never added this operator! I hate
- to type the typecast each time. ( integer(value shr shift) )
-
- EXAMPLE:
-
- writeln(sar(10,1)); { outputs 5 }
- writeln(sar(-10,1)); { outputs -5 }
-
-
- ───────────────────────────────────────────────────────────────────────────
- function sal(value:integer;shift:byte):integer;
-
- Shift arithmetic left. Same as SHL but maintains the signed (hi) bit.
-
- VALUE: integer value to shift.
- SHIFT: bits to shift
-
- EXAMPLE:
-
- writeln(sal(10,1)); { outputs 20 }
- writeln(sal(-10,1)); { outputs -20 }
-
- ───────────────────────────────────────────────────────────────────────────
- function ptr2hex(p:pointer):string;
-
- Converts a pointer to a string in hexadecimal format
-
- P: pointer to convert
-
- p := ptr($a000,20);
- writeln(ptr2hex(p)); { outputs A000:0014 }
-
- ───────────────────────────────────────────────────────────────────────────
- function word2hex(w:word):string;
-
- Converts a word value to hexadecimal format
-
- ───────────────────────────────────────────────────────────────────────────
- function byte2hex(b:byte):string;
-
- Converts a byte value to hexadecimal format
-
- ───────────────────────────────────────────────────────────────────────────
- procedure atexit(proc:QuitProc);
-
- Same as the function in C. Calls a quit procedure at exit. Can use
- many times. Chains multiple procedures. At the exit of the program
- the procedure are called in a LIFO fashion. (Last in-First out) The
- last atexit procedure is the first one to be called.
-
- PROC: procedure to call at the end of the program. Must be declared
- as a far procedure.
-
- EXAMPLE:
-
- Uses spx_fnc;
-
- {$F+ }
- procedure cleanup;
- begin
- { do my clean up routines here }
- end;
-
- procedure returnToTextMode;
- begin
- textmode(c80);
- end;
-
- begin
- atexit(cleanup);
- atexit(returnToTextMode);
- end.